package com.dgut.usermodule.dao;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

import com.dgut.usermodule.entity.Permission;


public interface PermJapRepository extends JpaRepository<Permission, Long>,JpaSpecificationExecutor<Permission>{
	@Modifying
	@Transactional
	@Query(value="INSERT INTO t_user_perm VALUES(:userId,:permId)",nativeQuery=true)
	int authorize(@Param("userId")Long userId,@Param("permId")Long permId);
	
	@Modifying
	@Transactional
	@Query(value="DELETE FROM t_user_perm WHERE User_id = :userId AND perms_id = :permId",nativeQuery=true)
	int cacelauthorize(@Param("userId")Long userId,@Param("permId")Long permId);
	
	@Modifying
	@Transactional
	@Query(value="DELETE FROM t_user_perm WHERE User_id = :userId",nativeQuery=true)
	int deleteauthorize(@Param("userId")Long userId);
}
